package com.lijie.test;

import com.lijie.ljblog.LjblogApplication;
import com.lijie.ljblog.service.impl.PersonServiceImpl;
import com.lijie.ljblog.service.impl.TestServiceImpl;
import com.lijie.ljblog.service.impl.UtilServiceImpl;
import com.lijie.ljblog.util.RedisUtils;
import lombok.SneakyThrows;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @Title: ljblog_springboot
 * @Description: ()
 * @Author:lijie
 * @Version:1.1.0
 * @since 2021/12/3
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = LjblogApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class PersonService {
    @Resource
    PersonServiceImpl personService;
    @Resource
    UtilServiceImpl utilService;
    @Resource
    RedisUtils redisUtils;
    @Resource
    TestServiceImpl testService;
    @Test
    public void redisTest(){
        try {
            Runnable runnable = new Runnable(){
                @SneakyThrows
                @Override
                public void run() {
                    for(int i=0;i<500;i++){
                        try {
                            Thread.sleep(1);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.println(Thread.currentThread().getName()+": "+addReadNums());
                    }
                }
            };
            ExecutorService executorService = Executors.newFixedThreadPool(5);
            executorService.execute(runnable);
            executorService.execute(runnable);
            try {
                TimeUnit.SECONDS.sleep(20);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("@Test线程执行完毕");
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    @Test
    public void weather(){
        utilService.getClimateByIP("112.86.216.2");
    }
    public Long addReadNums(){
        return redisUtils.incrBy("test", 1);
    }


    @Test
    public void test(){
        testService.update("1");
    }
}
